package main;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import markov.POSBigram;
import markov.SmartTagger;
import markov.WordBigram;

import eval.Evaluator;


public class Main {

    public static void main(String[]args){
	String  filename;

	if(args.length == 0)
	    filename = "in.txt"; //default file
	else
	    filename = args[0];


	//read dataset 
	MainReader reader = new MainReader(filename);
	ArrayList<String[]> dataset = reader.getWordTokens();
	ArrayList<Integer> dataIndex = reader.getSentences();

	//Original
	System.out.println("Confusion Matrix with original PPOS....");
	Evaluator  evaluator = new Evaluator(dataset);
	System.out.println("Original PPOS accuracy: " + evaluator.run());

	//Baseline tagger
	Reader r = new Reader();
	HashMap<String,Word> words = r.readTraining();
	
	System.out.println("Calcualting baseline tagger....");
	BaselineTagger tagger = new BaselineTagger(words);
	ArrayList<String[]> tags = tagger.tagWords(dataset);
	System.out.println("Done, preparing output and evalutaion....");
	evaluator = new Evaluator(tags);
	evaluator.PRINT_MATRIX = true;
	System.out.println("Baseline Tagger Accuracy: " + evaluator.run());

	//Initialize Smart Tagger
	POSBigram posbigram = new POSBigram(dataset);
	posbigram.run();
	WordBigram wordBigram = new WordBigram(dataset);
	wordBigram.run();
	SmartTagger n = new SmartTagger(dataIndex, dataset, posbigram.posProbability , wordBigram.wordProbabilityWordIndex);
	n.N_limit = 8; //Max word limit
	//Noisy Channel
	System.out.println("Calculating Noise Channel Model....");
	ArrayList<String[]> noisychaneloutput = n.noise_channel();
	System.out.println("Done, preparing output and evalutaion....");
	evaluator = new Evaluator(noisychaneloutput);
	System.out.println("Noise Channel Model Overral Accuracy: " + evaluator.run());


	// Hidden Markov
	System.out.println("Calculating Viterbi....");
	ArrayList<String[]> vibertioutput = n.viterbi();
	System.out.println("Done, preparing output and evalutaion....");
	evaluator = new Evaluator(vibertioutput);
	System.out.println("Viterbi Overral Accuracy: " + evaluator.run());
	System.out.println("output to viberti.out..");
	Outputter op = new Outputter();
	op.OutPut(vibertioutput,"viberti.out", filename);
    }
}
